<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
    // 1, 使用reduce求数组中所有元素的乘积， var arr = [2,3,4,5,6,7]
        var arr=[2,3,4,5,6,7];
        var res=arr.reduce((pre,cur)=>pre*cur);
        console.log(res);

    // 2, 使用reduce求数组中的最大数, var arr = [2,4,6,3,7,8,5]
        var arr2=[2,4,6,3,7,8,5];
        var res2=arr2.reduce((pre,cur)=>Math.max(pre,cur));
        console.log(res2);
    // 3, 使用indexOf完成数组去重.
        var arr3=[2,3,5,2,4,1,4,6,2,4,6];
        var arr4=arr3.reduce((pre,cur)=>{
            if(pre.indexOf(cur)==-1){
                pre.push(cur);
            }
            return pre;
        },[])
        console.log(arr4);

    // 4. 使用for-of求5! (1*2*3*4*5) 
        var arr5=[1,2,3,4,5];
        var t=1;
        for(var key of arr5){
            t*=key;
        }
        console.log(t);

    // 5, 使用for-of求1!+2!+3!+4!+5! 
        var arr6=[1,2,3,4,5];
        var m=0;
        for(var value of arr6){
            var sum=1;
            for(i=value;i>0;i--){
                sum*=i;
            }
            m+=sum;
        }
        console.log(m);

    // 6, 使用for-of求数组的最大数和最小数
    var arr7=[1,3,5,8,2,4,9,32,12];
    for(var value of arr7){
        for(var v of arr7){
            console.log(value);
            var max=Math.max(value,v);
            var min=Math.min(value,v);
        }
    }
    console.log(max,min);
    </script>
</body>
</html>